///mine.txt - An object that explodes whenever anyone gets close to it.
//Cell 0 - The number of creature spawned. Roster number, not in-game.
//Cell 1,2 - A stuff done flag. If > 0, this mine has been deactivated.
//Cell 3 - If 0, explodes for anyone. If 1, only party members. If 2, only for pc.


beginobjectscript; // mine

variables;
short near_char;
short r1;
short icon_off = 0;

body;

beginstate INIT_STATE;
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; // door closed, waiting
	if ((get_memory_cell(1) > 0) || (get_memory_cell(2) > 0)) {
		if (get_sdf(get_memory_cell(1),get_memory_cell(2)) > 0) {
			if (icon_off == 0)
				set_object_icon(ME,15);
			icon_off = 1;
			end();
			}
		}
	if (icon_off == 1) {
		icon_off = 0;
		set_object_icon(ME,0);
		}
	near_char = -1;	
	if (get_memory_cell(3) == 0)
		near_char = get_nearest_char(2);
		else if (get_memory_cell(3) == 1)
			near_char = get_nearest_good_char(2);
			else {
				if (dist_to_pc() <= 2)
					near_char = pc_num();
				}
	if (near_char >= 0) {
		pc_heard_sound(152);
		run_sparkles_on_object(ME,3,1,0);
		spawn_creature(get_memory_cell(0));
		kill_object(ME,0);
		}
break;

beginstate 3;
	
break;